from django.db import models


# Create your models here.
class Category(models.Model):
    cname = models.CharField(max_length=30, unique=True, verbose_name='类别名称')

    # unique在表中有唯一值
    def __str__(self):
        return self.cname

    class Meta:
        db_table = 't_category'
        verbose_name_plural = '类别'

class Tag(models.Model):
    tname = models.CharField(max_length=20, unique=True, verbose_name='标签名称')

    def __str__(self):
        return self.tname

    class Meta:
        db_table = 't_tag'
        verbose_name_plural = '标签'




from mdeditor.fields import MDTextField
class Post(models.Model):
    title = models.CharField(max_length=100, unique=True, verbose_name='标题')  # 标题
    desc = models.CharField(max_length=200, verbose_name='简介')
    content = MDTextField(verbose_name='内容')  # 内容
    created = models.DateTimeField(auto_now_add=True)  # 创建时间
    modified = models.DateTimeField(auto_now=True)
    isdelete = models.BooleanField(default=False, verbose_name='是否删除')
    category = models.ForeignKey(Category, on_delete=models.CASCADE, verbose_name='所属类别')
    tag = models.ManyToManyField(Tag, verbose_name='所属标签')

    def __str__(self):
        return self.title

    class Meta:
        db_table = 't_post'
        # 数据库中表的名字
        verbose_name_plural = '帖子'

class User(models.Model):
    nick_name=models.CharField(max_length=16,verbose_name='昵称')
    username=models.CharField(max_length=20,unique=True,verbose_name='用户邮箱')
    password=models.CharField(max_length=100,verbose_name='密码')
    class Meta:
        db_table = 't_user'
        # 数据库中表的名字
        verbose_name_plural = '用户数据'
    def __str__(self):
        return self.nick_name


class comment(models.Model):
    author=models.CharField(max_length=16,verbose_name="用户名")
    date_at=models.DateTimeField(auto_now_add=True)
    content = models.CharField(max_length=100,verbose_name='内容')
    title = models.CharField(max_length=100, verbose_name='标题',default='')
    class Meta:
        db_table = 't_comment'
        # 数据库中表的名字
        verbose_name_plural = '用户评论'
    def __str__(self):
        return self.author


class like(models.Model):
    title = models.CharField(max_length=100, verbose_name='标题')
    author = models.CharField(max_length=16, verbose_name="用户名")
    aa=models.BooleanField(default='false',verbose_name='点赞')
    class Meta:
        db_table = 't_like'
        # 数据库中表的名字
        verbose_name_plural = '用户点赞'
    def __str__(self):
        return self.author

class Collect(models.Model):
    title = models.CharField(max_length=100, verbose_name='标题')
    author = models.CharField(max_length=16, verbose_name="用户名")
    class Meta:
        db_table = 't_collect'
        # 数据库中表的名字
        verbose_name_plural = '用户收藏'
    def __str__(self):
        return self.author
